/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package control;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author root
 */
public class MessageFactory {
    public static FacesMessage  createMessage(FacesMessage.Severity severity, String key, Object... params)
    {
        String summary = "?? key " + key + " not found ??";
        String detail = null;
        FacesContext context = FacesContext.getCurrentInstance();
        String name = context.getApplication().getMessageBundle();

        ResourceBundle bundle =ResourceBundle.getBundle(name);
        try {
            summary = bundle.getString(key);
            summary = MessageFormat.format(summary, params);
            detail = bundle.getString(key + "_detail");
            detail = MessageFormat.format(detail, params);
        } catch (MissingResourceException e) {}
        
        return new FacesMessage(severity, summary, detail);
    }
}
